package com.nf.controller.home;

import com.google.gson.Gson;
import com.nf.controller.BaseServlet;
import com.nf.dao.CommentInfoDao;
import com.nf.dao.impl.CommentInfoDaoImpl;
import com.nf.entity.CommentInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * 编写servlet，实现根据影片ID ，查询出其所有评论
 */
@WebServlet("/api/SelectCommentsByFilmIdServlet.do")
public class SelectCommentsByFilmIdServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int filmId= Integer.parseInt(req.getParameter("filmId"));

        CommentInfoDao dao=new CommentInfoDaoImpl();
        List<CommentInfo> list= dao.selectById(filmId);

        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();

        out.print(new Gson().toJson(successJson(list)));

        out.flush();
        out.close();
    }
}
